package com.wenwei.sharebox.activity;

import com.jaeger.library.StatusBarUtil;
import com.wenwei.sharebox.R;
import com.wenwei.sharebox.base.BaseActivity;
import com.wenwei.sharebox.base.Constant;
import com.wenwei.sharebox.bean.UserLoginBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;
import com.wenwei.sharebox.utils.RogerSPUtils;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.functions.Action1;

/**
 * Created by Administrator on 2017/7/6.
 */
public class SplashActivity extends BaseActivity {
    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {
        super.initView();
        StatusBarUtil.setTranslucent(this, 30);
    }

    @Override
    protected void initData() {
        super.initData();
        UserLoginBean ub = RogerSPUtils.getObject(mContext, Constant.SP_USER_LOGIN_RESULT,UserLoginBean.class);
        if(ub != null){
            getUserInfo();
        }
        Observable.just("").delay(3, TimeUnit.SECONDS).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                goActivity(mContext,HostActivity.class);
                finish();
            }
        });
    }

    private BaseSubscriber<UserLoginBean> userInfoSubscriber;
    private void getUserInfo(){
        userInfoSubscriber = new BaseSubscriber<UserLoginBean>(mContext) {
            @Override
            public void onSuccess(UserLoginBean userLoginBean) {
                RogerSPUtils.putObject(mContext, Constant.SP_USER_LOGIN_RESULT,userLoginBean);
            }
        };
        ApiManager.getInstance().getUserInfo(userInfoSubscriber);
    }


}
